package Friday.th2;
public class CompanySalary {
    public static void main(String[] args) {
        //为存放员工的引用申请空间
        Employee employee[]=new Employee[29];
        //创建年薪员工的引用
        for(int i=0;i<10;i++){
            employee[i]= new YearWorker();
        }
        //创建月薪员工的引用
        for (int i=10;i<20;i++){
            employee[i]=new MonthWorker();
        }
        //创建周薪员工的引用
        for (int i=20;i<29;i++){
            employee[i]=new Weekworker();
        }
        //使用Company类的匿名对象计算员工的总工资
        System.out.println("总工资:"+(new Company(employee)).salariesPay()+"元");
    }
}
class Company {
    Employee[] employee;
    double salaries = 0;
    Company(Employee[] employee) {
        this.employee=employee;//初始化成员
    }
    public double salariesPay() {
        for (Employee i:employee){
             salaries+=i.earnings();
         }
        return salaries;
        //计算公司所有员工薪水总和
    }
}
abstract class Employee {
    public abstract double earnings();
}
class YearWorker extends Employee {
    public double earnings() {
        return 1000000;
    }
    //重写earnings ()方法给出雇员一年的年薪
}
class MonthWorker extends Employee {
    public double earnings() {
        return 10000*12;
    }
    //重写earnings()方法自定义每月薪水,由此计算出雇员-年的年薪
}
class Weekworker extends Employee {
    public double earnings() {
        return 100*12*4;
    }
//重写earnings ()方法自定义每周薪水,由此计算出雇员-一年的年薪
}
